#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e7+5;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL p[maxn];
LL num[maxn];
int main(void){
   num[0]=0;
   memset(p,-1,sizeof(p));
   for(LL i=1;i<maxn;i++){
       for(LL j=i;j<maxn;j+=i){
          num[j]+=i;
       }
   }
   for(LL i=1;i<maxn;i++){
      if(num[i]>maxn) continue;
      if(p[num[i]]==-1){
        p[num[i]]=i;
      }
   }
   int t;t=read();
   while(t--){
      int c;c=read();
      printf("%d\n",p[c]);
   }
   return 0;
}
